﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TienLen
{
    /// <summary>
    /// The invite user selection form.
    /// </summary>
    public partial class InviteUser : Form
    {
        private MSNPSharp.Contact[] contacts;

        /// <summary>
        /// Selected invited contacts.
        /// </summary>
        public MSNPSharp.Contact[] InvitedContacts
        {
            get { return contacts; }
        }

        public InviteUser(TreeNodeCollection users)
        {
            InitializeComponent();

            // Create a blank 16x16 image
            Graphics g = Graphics.FromImage(new Bitmap(16, 16) as Image);
            g.Clear(Color.White);

            // Set the ImageList's for the custom TreeView's
            accounts.ImageList = new ImageList()
            {
                ImageSize = new Size(16, 16),
                Images = { new Bitmap(16, 16, g), Image.FromFile(Application.StartupPath + @"\img\other\wlm-online.png") },
                ColorDepth = ColorDepth.Depth32Bit
            };

            invites.ImageList = new ImageList()
            {
                ImageSize = new Size(16, 16),
                Images = { new Bitmap(16, 16, g), Image.FromFile(Application.StartupPath + @"\img\other\wlm-online.png") },
                ColorDepth = ColorDepth.Depth32Bit
            };

            // Retrieve online users with Tien Len Client
            foreach (TreeNode user in users)
                accounts.Nodes.Add(user.Clone() as TreeNode);
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            foreach (TreeNode nodes in accounts.SelectedNodes)
            {
                accounts.DeselectNode(nodes);
                invites.Nodes.Add(nodes.Clone() as TreeNode);
            }

            accounts.RemoveSelectedNodes();
        }

        private void btnRemove_Click(object sender, EventArgs e)
        {
            foreach (TreeNode nodes in invites.SelectedNodes)
            {
                invites.DeselectNode(nodes);
                accounts.Nodes.Add(nodes.Clone() as TreeNode);
            }

            invites.RemoveSelectedNodes();
        }

        private void btnInvite_Click(object sender, EventArgs e)
        {
            if (invites.Nodes.Count == 0)
                MessageBox.Show("You don't have any invited users.", "No Invited Users", MessageBoxButtons.OK, MessageBoxIcon.Information);
            else
            {
                contacts = new MSNPSharp.Contact[invites.Nodes.Count];

                for (int x = 0; x < invites.Nodes.Count; x++)
                    contacts[x] = invites.Nodes[x].Tag as MSNPSharp.Contact;

                this.DialogResult = DialogResult.OK;
            }
        }
    }
}
